package org.springblade.common.config;

import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ArchiveOssRule implements OssRule{

	public static final String MANAGER_TENANT_ID="000000";
	public static final String BUCKET_NAME_SUFFIX="-archives";
	private String tenantId;

	@Value("${oss.bucket-name}")
	private String bucket;

	public String bucketName(String bucketName) {
		return this.bucketName();
	}

	public String bucketName() {
		return bucket;
	}

	public String fileName(String originalFilename) {
		return originalFilename;
	}


	public String getTenantId() {
		//只有管理组可以设置其他租户id

		if(!StringUtils.isEmpty(tenantId)) {
			return tenantId;
		}

		if(!StringUtils.isEmpty(AuthUtil.getTenantId())) {
			return AuthUtil.getTenantId();
		}

		return "";

	}

	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}


}
